import instance from '../http'

const baseURL = window.globalConfig.baseURL
const requests = {
  requestExample: {
    method: 'get',
    url: baseURL + 'exampleUrl'
  }
}

const createHttpReq = type => {
  return (...args) => {
    if (requests[type].method === 'get') {
      requests[type].params = args[0]
    } else {
      requests[type].data = args[0]
      if (args.length > 1) {
        requests[type].params = args[1]
      }
    }
    return instance(requests[type])
  }
}

export const requestExample = createHttpReq('requestExample')